﻿using System;
using System.Collections.Generic;
using System.Text;

using ApplicationLibrary.SqlConnector;
using ApplicationLibrary.DBManager;

#region RegisterTable
public class RegisterSystemTable : RegisterTable
{
    public override int Code() { return 0; }
    override protected int CurrentVersion() { return 1; }
    override protected string Module() { return "ApplicationManager"; }

    public override Version DllVersion
    {
        get
        {
            return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
        }
    }

    override protected bool CreateDBTables()
    {
        SqlCreateTable newTable = new SqlCreateTable(SqlABConnection);
        #region Users Table
        if (SearchTable(AM_Users.Name))
        {
            newTable.NewTable(AM_Users.Name);
            newTable.AddColumn(AM_Users.Username);
            newTable.AddColumn(AM_Users.Password);
            newTable.AddColumn(AM_Users.Surname);
            newTable.AddColumn(AM_Users.UserType);
            newTable.AddColumn(AM_Users.Expired);
            newTable.AddColumn(AM_Users.ExpireDate);
            newTable.AddColumn(AM_Users.ChangePassword);
            newTable.AddColumn(AM_Users.Blocked);
            newTable.AddPrimaryKey(AM_Users.Username);
            newTable.Create();
        }
        #endregion
        #region Lock Table
        if (SearchTable(AM_Locks.Name))
        {
            newTable.NewTable(AM_Locks.Name);
            newTable.AddColumn(AM_Locks.ComputerName);
            newTable.AddColumn(AM_Locks.Username);
            newTable.AddColumn(AM_Locks.TableName);
            newTable.AddColumn(AM_Locks.LockKey);
            newTable.AddColumn(AM_Locks.LockDate);
            newTable.AddPrimaryKey(AM_Locks.TableName, AM_Locks.LockKey);
            newTable.Create();
        }
        #endregion
        #region DBVersion
        if (SearchTable(AM_Version.Name))
        {
            newTable.NewTable(AM_Version.Name);
            newTable.AddColumn(AM_Version.Module);
            newTable.AddColumn(AM_Version.Version);
            newTable.Create();
        }
        #endregion
        #region AM_Descriptions

        if (SearchTable(AM_Descriptions.Name))
        {
            newTable.NewTable(AM_Descriptions.Name);

            newTable.AddColumn(AM_Descriptions.ID);
            newTable.AddColumn(AM_Descriptions.Category);
            newTable.AddColumn(AM_Descriptions.Description);

            newTable.AddPrimaryKey(new iColumn[] { AM_Descriptions.ID });

            newTable.Create();
        }
        #endregion
        #region AM_Counter
        //newTable.DropTable(AM_Counter.Name);

        if (SearchTable(AM_Counter.Name))
        {
            newTable.NewTable(AM_Counter.Name);

            newTable.AddColumn(AM_Counter.Year);
            newTable.AddColumn(AM_Counter.Type);
            newTable.AddColumn(AM_Counter.Description);
            newTable.AddColumn(AM_Counter.HasPrefix);
            newTable.AddColumn(AM_Counter.PrefixRO);
            newTable.AddColumn(AM_Counter.PrefixValue);
            newTable.AddColumn(AM_Counter.PrefixMask);
            newTable.AddColumn(AM_Counter.PrefixType);
            newTable.AddColumn(AM_Counter.PrefixSep);
            newTable.AddColumn(AM_Counter.HasSuffix);
            newTable.AddColumn(AM_Counter.SuffixRO);
            newTable.AddColumn(AM_Counter.SuffixValue);
            newTable.AddColumn(AM_Counter.SuffixMask);
            newTable.AddColumn(AM_Counter.SuffixType);
            newTable.AddColumn(AM_Counter.SuffixSep);
            newTable.AddColumn(AM_Counter.CodeType);
            newTable.AddColumn(AM_Counter.CodeLen);
            newTable.AddColumn(AM_Counter.CodeKey);

            newTable.AddPrimaryKey(new iColumn[] { AM_Counter.Year, AM_Counter.Type });

            newTable.Create();
        }
        #endregion
        #region AM_CounterValue

        if (SearchTable(AM_CounterValue.Name))
        {
            newTable.NewTable(AM_CounterValue.Name);

            newTable.AddColumn(AM_CounterValue.Type);
            newTable.AddColumn(AM_CounterValue.Code);
            newTable.AddColumn(AM_CounterValue.Description);
            newTable.AddColumn(AM_CounterValue.TextValue);
            newTable.AddColumn(AM_CounterValue.NumericValue);

            newTable.AddPrimaryKey(new iColumn[] { AM_CounterValue.Type, AM_CounterValue.Code });

            newTable.Create();
        }
        #endregion

        return true;
    }
    override protected bool UpdateDBTables()
    {
        return true;
    }
}
#endregion